<cfsetting enablecfoutputonly="yes">
<!--- 
|| LEGAL ||
$Copyright: Daemon Pty Limited 1995-2003, http://www.daemon.com.au $
$License: Released Under the "Common Public License 1.0", http://www.opensource.org/licenses/cpl.php$

|| VERSION CONTROL ||
$Header: /cvs/farcry/farcry_mollio/webskin/dmEvent/displayTeaserCalendarSmall.cfm,v 1.1 2006/04/04 06:03:54 gstewart Exp $
$Author: gstewart $
$Date: 2006/04/04 06:03:54 $
$Name:  $
$Revision: 1.1 $

|| DESCRIPTION || 
$Description: dmEvent -- calendar listing$
$TODO: $

|| DEVELOPER ||
$Developer: Brendan Sisson (brendan@daemon.com.au) $
--->
<!--- @@displayname: Small Calendar --->
<!--- @@author: Brendan Sisson --->

<cfimport taglib="/farcry/core/tags/webskin" prefix="skin">

<cfparam name="arguments.stParam" default="#structNew()#" />

<cfparam name="URL.param2" default="#Month(now())#">
<cfparam name="URL.param1" default="#Year(now())#">
<cfset calDate = CreateDate(URL.param1, URL.param2, '01') />

<!--- loop over number of months to display --->
<cfloop from="0" to="#stobj.months-1#" index="displayMonth">
	<!--- work out year and month --->
	<cfset month = "#Month(dateadd("m",displayMonth,calDate))#">
	<cfset year = "#Year(dateadd("m",displayMonth,calDate))#">

	<!---Find the start day  the month--->
	<cfset start_day = DayOfWeek(createdate("#year#","#month#","1"))>
	
	<!---Find the total no of days in the month--->
	<cfset total_days_in_month = DaysInMonth(createdate("#year#","#month#","1"))>
	
	<!---Find the end day of the month--->
	<cfset end_day = DayOfWeek(createdate("#year#","#month#","#total_days_in_month#"))>
	
	<!--- show calendar --->
	<cfoutput>
	<table cellpadding="0" cellspacing="0" width="228" class="calendar">
		<thead>
			  <tr class="monthname">
	<cfset prevDate = DateAdd('M', -1, createdate("#year#","#month#","1")) />
	<cfset nextDate = DateAdd('M', 1, createdate("#year#","#month#","1")) />
	<td><a href="/go/events/#DateFormat(prevDate, 'YYYY/MM')#" class="nav-l">&laquo;</a></td>
	<td colspan="5" align="center"><a href="###monthasstring(month)##year#" class="nav-h">#monthasstring(month)#&nbsp;#year#</a></td>
	<td><a href="/go/events/#DateFormat(nextDate, 'YYYY/MM')#" class="nav-r">&raquo;</a></td>

		</thead>
		<tbody>
		<!--- show days of week --->
		<tr class="daynames">
			<cfloop from="1" to="7" index="d">
				<th><acronym title="<cfoutput>#dayofweekasstring(d)#</cfoutput>"><cfoutput>#left(dayofweekasstring(d),1)#</cfoutput></acronym></th>
			</cfloop>
		</tr>
		</cfoutput>
		<cfset week_day = start_day>
		<cfset display_day = 1>
		<cfset week=1>
		<!--- loop through calendar month --->
		<cfloop condition = "#display_day# LTE #total_days_in_month#">
			<!--- start new week --->
			<cfoutput><tr class="days"></cfoutput>
				<!--- loop through week --->
				<cfloop condition = "#week_day# LTE 7">
					<cfloop condition = "#start_day# NEQ 1">
						<!--- date is in previous month --->
						<cfoutput><td>&nbsp;</td></cfoutput>
						<cfset start_day = start_day - 1>
					</cfloop>
					<cfif display_day LTE total_days_in_month>
						<cfset currentDate = DateFormat(createdate("#year#","#month#","#display_day#"))>
						<!--- check for event --->
						<cfset eventDisplayed = 0>
						<cfset eventTitles = "">
						
						<cfquery dbtype="query" name="qDayEvents" result="res">
						SELECT * FROM arguments.stParam.qEvents									
						WHERE startDate <= '#DateFormat(DateAdd("d", 1, currentDate))#'
						AND endDate >= '#currentDate#'
						</cfquery>
						<cfif qDayEvents.recordCount>
							<cfset eventDisplayed = 1>
							<cfloop query="qDayEvents">
								<cfif len(eventTitles)>
									<cfset eventTitles = eventTitles & "#chr(13)##chr(13)##qDayEvents.title##chr(13)##qDayEvents.location#">
								<cfelse>
									<cfset eventTitles = eventTitles & "#qDayEvents.title##chr(13)##qDayEvents.location#">
								</cfif>
								<cfset eventObjectid = qDayEvents.objectid>
							</cfloop>
						</cfif>
		
						<!--- check if display day as event or empty --->
						<cfsavecontent variable="tdClass">
							<cfif currentdate eq dateformat(now()) OR eventDisplayed><cfoutput>class="</cfoutput></cfif>
							<cfif currentdate eq dateformat(now())><cfoutput>caltoday</cfoutput></cfif>
							<cfif eventDisplayed><cfoutput>item" title="#eventTitles#</cfoutput></cfif>
							<cfif currentdate eq dateformat(now()) OR eventDisplayed><cfoutput>"</cfoutput></cfif>
						</cfsavecontent>						
						
						<cfoutput><td #tdClass#></cfoutput>
						
						<!--- display date --->
						<cfif eventDisplayed>
							<skin:buildLink objectid="#eventObjectid#" class="eventLink"><cfoutput>#display_day#</cfoutput></skin:buildLink>
						<cfelse>
							<cfoutput>#display_day#</cfoutput>
						</cfif>
						<cfoutput></td></cfoutput>
					<cfelse>
						<cfloop condition="#end_day# NEQ 7">
							<!--- date is in next month --->
							<cfset end_day = end_day + 1>
							<cfoutput><td>&nbsp;</td></cfoutput>
						</cfloop>	
					</cfif>
					<cfset week_day = week_day + 1>
					<cfset display_day = display_day + 1>
				</cfloop>
			<cfoutput></tr>
			</cfoutput>
			<cfset week_day = 1>
			<cfset week = week + 1>
		</cfloop>
	<cfoutput>
	</tbody></table>
	</cfoutput>
</cfloop>
<cfsetting enablecfoutputonly="no">